<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Class与Style绑定</title>
    <script src="vue.js"></script>
    <style>
        .box {
            width: 100%;
            height: 100px;
            border-bottom: 1px solid lightgray;
        }
    </style>
</head>
<body>
<!--绑定HTML Class-->
<!--对象语法-->
<div id="app1" class="static"
     v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>
<!--<div v-bind:class="classObject"></div>-->
<script>
    let app1 = new Vue({
        el: '#app1',
        data: {
            isActive: true,
            hasError: false
        }
//        data: {
//            classObject: {
//                active: true,
//                'text-danger': false
//            }
//        }

//        data: {
//            isActive: true,
//            error: null
//        },
//        computed: {
//            classObject: function () {
//                return {
//                    active: this.isActive && !this.error,
//                    'text-danger': this.error && this.error.type === 'fatal'
//                }
//            }
//        }
    })
</script>

<!--数组语法-->
<div id="app2" v-bind:class="[activeClass, errorClass]"></div>
<div v-bind:class="[isActive ? activeClass : '', errorClass]"></div>
<div v-bind:class="[{ active: isActive }, errorClass]"></div>
<script>
    let app2 = new Vue({
        el:'#app2',
        data: {
            activeClass: 'active',
            errorClass: 'text-danger'
        }
    })
</script>
<!--渲染成：<div class="active text-danger"></div>-->

<!--绑定内联样式-->
<!--对象语法-->
<div id="app3" v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div v-bind:style="styleObject"></div>
<script>
    let app3 = new Vue({
        el:'#app3',
        data: {
            activeColor: 'red',
            fontSize: 30
        }
//        data: {
//            styleObject: {
//                color: 'red',
//                fontSize: '13px'
//            }
//        }
    })
</script>
<!--v-bind:style 的数组语法可以将多个样式对象应用到同一个元素上：-->
<div v-bind:style="[baseStyles, overridingStyles]"></div>
<!--这样写只会渲染数组中最后一个被浏览器支持的值。在本例中，
如果浏览器支持不带浏览器前缀的 flexbox，那么就只会渲染 display: flex。-->
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div>

<!------------------------------------------------------------------------------>
<!--todoList-->
<div id="todo-list-example">
    <input
            v-model="newTodoText"
            v-on:keyup.enter="addNewTodo"
            placeholder="Add a todo"
    >
    <ul>
        <li
                is="todo-item"
                v-for="(todo, index) in todos"
                v-bind:key="todo.id"
                v-bind:title="todo.title"
                v-on:remove="todos.splice(index, 1)"
        ></li>
    </ul>
</div>
<script>
    Vue.component('todo-item', {
        template: '\
    <li>\
      {{ title }}\
      <button v-on:click="$emit(\'remove\')">X</button>\
    </li>\
  ',
        props: ['title']
    });
    new Vue({
        el: '#todo-list-example',
        data: {
            newTodoText: '',
            todos: [
                {
                    id: 1,
                    title: 'Do the dishes',
                },
                {
                    id: 2,
                    title: 'Take out the trash',
                },
                {
                    id: 3,
                    title: 'Mow the lawn'
                }
            ],
            nextTodoId: 3
        },
        methods: {
            addNewTodo: function () {
                this.todos.push({
                    id: this.nextTodoId++,
                    title: this.newTodoText
                });
                this.newTodoText = ''
            }
        }
    })
</script>


</body>


</html>














